package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.GoodsReturn;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.GoodsReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 田沛凌
 * @time 2017/8/3 13:27
 */
@RestController
@RequestMapping(value = "/goodsReturn", method = RequestMethod.POST)
public class GoodsReturnController extends BaseController{

    private GoodsReturnService goodsReturnService;
    @Autowired
    public void setGoodsReturnService(GoodsReturnService goodsReturnService) {
        this.goodsReturnService = goodsReturnService;
    }

    /**
     * 新增缺货登记
     * @param goodsReturn；
     */
    @RequestMapping("/addGoodsReturn")
    public BaseResponse addGoodsReturn(GoodsReturn goodsReturn){
        goodsReturn.setCreateUser(super.getLoginUserId());
        goodsReturnService.addGoodsReturn(goodsReturn);
        return AppResponse.OK;
    }

    /**
     * 缺货数据查询(分页)
     * @param goodsReturn；
     * @return 缺货数据
     */
    @RequestMapping("/pageGoodsReturn")
    public BaseResponse pageGoodsReturn(GoodsReturn goodsReturn){
        List<Long> prisonPower = super.getPrisonPower();
        List<Long> supplierPower = super.getSupplierPower();
        goodsReturn.setPrisonPower(prisonPower);
        goodsReturn.setSupplierPower(supplierPower);
        List<GoodsReturn> list = goodsReturnService.list(goodsReturn);
        return new AppResponse(new PageInfo<>(list));
    }

    /**外网
     * 确认补货
     * @param idStr 缺货单ID集合
     */
    @RequestMapping("/confirmBackGoods")
    public BaseResponse confirmBackGoods(String idStr){
        goodsReturnService.confirmBackGoods(idStr);
        return AppResponse.OK;
    }
    /**内网
     * 确认收货
     * @param idStr 缺货单ID集合
     */
    @RequestMapping("/confirmGoodsReturn")
    public BaseResponse confirmGoodsReturn(String idStr){
        goodsReturnService.confirmGoodsReturn(idStr);
        return AppResponse.OK;
    }
}
